program geo1;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
  x1, y1, x2, y2, x0, y0, xp, yp, a, b, c, d, p1, p2 : integer;


begin
  writeln('write the coordinats of ur point:');
  read(x0, y0);
  writeln('write the coordinats of ur segment:');
  read(x1, y1, x2, y2);
  a:=y1-y2;
  b:=x1-x2;
  c:=x1*y2-x2*y1;
  d:=round((a*x0+b*x0+c)/(sqrt(a*a+b*b)));
  xp:=round(x0-(a*d)/(sqrt(a*a+b*b)));
  yp:=round(y0-(b*d)/(sqrt(a*a+b*b)));
  if (((x2-xp)*(x1-xp)<=0) and ((y2-yp)*(y1-yp)<=0)) then
    writeln(d)

    else begin

  p1:=round(sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0)));
  p2:=round(sqrt((x2-x0)*(x2-x0)+(y2-y0)*(y2-y0)));
  if (p1<=p2) then
    writeln(p1)
    else
    writeln(p2);
    end;
    readln;
    readln;
end.
